package 等待唤醒机制;

public class Foodie extends Thread{
    @Override
    public void run() {
        while (true){
            synchronized (Desk.lock){
                if (Desk.count == 0){
                    break;
                }else{
                    // 判断桌子上是否有食物，如果没有则等待
                    if (Desk.foodFlag == 0){// 没有食物
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else{// 有食物
                        Desk.count--;
                        System.out.println("吃货还能吃" + Desk.count + "碗饭");
                        Desk.foodFlag--;
                        Desk.lock.notify();
                    }
                }
            }
        }
    }
}
